//
//  AppDelegate.m
//  saler-ios
//
//  Created by 王亚陆 on 17/5/27.
//  Copyright © 2017年 sayimba. All rights reserved.
//

#import "AppDelegate.h"
#import "WelcomeViewController.h"
#import "LoginViewController.h"
@interface AppDelegate ()
{
    RootViewController *rootVC;
    UIImageView * viewImage ;
    Common * com;
}
@property (nonatomic,strong) WelcomeViewController *welcomeVC;

@property (nonatomic,strong) LoginViewController *loginVC;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = WhiteColor;
    com = [[Common alloc]init];
    

    [self createRooVC];
    [self chooseRootVC];
    
    
    [self.window makeKeyAndVisible];
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    
    return YES;
}

-(void)chooseRootVC
{
    
    BOOL flag = [[NSUserDefaults standardUserDefaults]boolForKey:@"firstIn"];
    flag = YES;
    if (flag == YES) {
        self.window.rootViewController = rootVC;
    } else {
        self.window.rootViewController = self.loginVC;
    }
}

-(WelcomeViewController *)welcomeVC
{
    if (!_welcomeVC) {
        _welcomeVC = [[WelcomeViewController alloc]init];
        __weak typeof(self) weakSelf = self;
        
        _welcomeVC.callBack = ^(){
            [weakSelf chooseRootVC];
        };
    }
    return _welcomeVC;
}


-(LoginViewController *)loginVC{
    
    
    if (!_loginVC) {
        _loginVC = [[LoginViewController alloc]init];
        __weak typeof(self) weakSelf = self;
        
        _loginVC.callBack = ^(){
            [weakSelf chooseRootVC];
        };
    }
    return _loginVC;
}

-(void)createRooVC
{
    rootVC = [RootViewController defaultsTabBar];;
    
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    viewImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, Main_Width, Main_height)];
    viewImage.image = [UIImage imageNamed:@"1"];
    [self.window addSubview:viewImage];
}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    [self performSelector:@selector(delayMethod) withObject:nil afterDelay:1];

}
-(void)delayMethod{
    
    [viewImage removeFromSuperview];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
